package command.fileComm;

import command.Command;
import empty.files.MyFile;
import empty.log.Log;
import model.fileModel.FileModel;
import model.log.LogModel;
import server.ServerThread;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

public class RenameCommand extends Command {
    @Override
    public void excute() {

    }

    @Override
    public void excute(ServerThread st) {
        MyFile myFile = (MyFile) this.o;
        Path path1 = Paths.get(path);
        try {
            File file = path1.toFile();
            file.renameTo(new File(path1.getParent().toString() + "\\" + myFile.getName()));
            int n = new FileModel().updateFile(myFile);
            if(n != 0){
                // log
                Log log = new Log("重命名" + myFile.getType() + "："+path1.toAbsolutePath() + " --> " + myFile.getName(),st.getUser().getId(),myFile.getCreate_time());
                new LogModel().insertLog(log);

                this.r = true;
            }
        }
        catch (Exception ex){
            this.e = ex;
            this.r = false;
        }
    }
}
